<!--{template librarylist/pc/components/right/file/tag/js}-->
<!--{template librarylist/pc/components/right/file/color/js}-->
<!--{template librarylist/pc/components/right/file/folder/js}-->
<!--{template librarylist/pc/components/right/file/tab/js}-->
<script type="text/javascript">
	let RightFileMixin = {
		mixins:[RightTagMixin,RightColorMixin,RightFolderMixin,RightTabMixin],
		methods:{
			async RightFileNameChange(val){//文件名称修改
				var self = this;
				var res = await axios.post('{MOD_URL}&op=library&do=lable&operation=save&flag=name',{
					val:val,
					rid:this.RightActiveRid[0],
					appid:this.DocumentAppid
				});
				let curr = this.ImageDataParam.data.find(function(current){
					return current.rid == self.RightActiveRid[0];
				});
				if(res.data.success){
					// curr.name = val;
					self.$refs.RefImageLayout.UpdateData(curr.rid,'name',val);
				}else{
					self.$message.error(res.data.msg || '保存失败');
				}
				
			},
			async RightFileDescChange(val){//描述修改
				var self = this;
				if(this.RightType == 'folder'){
					var param = {
						val:val,
						fid:this.LeftTree.Currentkey,
						appid:this.DocumentAppid,
					}
					if(self.RightActivefid && self.RightActivefid.length){
						param['fid'] = self.RightActivefid.join(',');
					}else{
						param['fid'] = self.LeftTree.Currentkey;
					}
				}else{
					var param = {
						val:val,
						rid:this.RightActiveRid.join(','),
						appid:this.DocumentAppid,
					}
				}
				var res = await axios.post('{MOD_URL}&op=library&do=lable&operation=save&flag=desc',param);
				if(res.data.success){
				}else{
					self.$message.error(res.data.msg || '保存失败');
				}
			},
			async RightFileLinkChange(val){//链接修改
				var self = this;
				var res = await axios.post('{MOD_URL}&op=library&do=lable&operation=save&flag=link',{
					val:val,
					rid:this.RightActiveRid.join(','),
					appid:this.DocumentAppid
				});
				if(res.data.success){
					
				}else{
					self.$message.error(res.data.msg || '保存失败');
				}
			},
			async RightFileTagDelete(flag,data){//标签删除
				var self = this;
				let curr = this.RightData.filedsData.find(function(current){
					return current.flag == flag;
				});
				if(!curr)return false;

				let currIndex = curr.value.indexOf(data.tid);
				curr.value.splice(currIndex,1);


				let tcurr = curr.data.findIndex(function(current){
					return current.tid == data.tid;
				});
				curr.data.splice(tcurr,1);

				var vals = [];
				var texts = [];
				for(var n in curr.data){
					texts.push(curr.data[n].tagname);
					vals.push(curr.data[n].tid);
				}


				if(this.RightType == 'folder'){
					var param = {
						flag:'tag',
						val:vals.join(','),
						fid:this.RightActivefid.join(','),
						appid:this.DocumentAppid,
					}
				}else{
					var param = {
						flag:'tag',
						val:vals.join(','),
						rid:this.RightActiveRid.join(','),
						appid:this.DocumentAppid,
					}
				}

				var {data: res} = await axios.post(MOD_URL+'&op=library&do=lable&operation=save',param);
				if(res.success){
					let text = [];
					let val = [];
					for (let findex = 0; findex < res.data.tag.length; findex++) {
						const element = res.data.tag[findex];
						text.push(element.tagname);
						val.push(element.tid);
					}
					for (let index = 0; index < res.data.rid.length; index++) {
						const element = res.data.rid[index];
						let curr = this.ImageDataParam.data.find(function(current){
							return current.rid == element;
						});
						if(curr){
							self.$refs.RefImageLayout.UpdateData(element,'tags',text);
							curr.tags = text;
						}
					}
				}else{
					self.$message.error(res.data.msg || '删除标签失败');
				}
			},
			async RightFileGradeChange(val){//评分修改
				var self = this;
				var res = await axios.post('{MOD_URL}&op=library&do=lable&operation=save&flag=grade',{
					val:val,
					rid:this.RightActiveRid.join(','),
					appid:this.DocumentAppid
				});
				
				if(res.data.success){
					for(var r in self.RightActiveRid){
						self.$refs.RefImageLayout.UpdateData(self.RightActiveRid[r],'grade',val);
					}
				}else{
					self.$message.error(res.data.msg || '保存失败');
				}
			},
			async RightFileLevelChange(val){//密级修改
				var self = this;
				let dpaths = [];
				if(this.ImageDataParam.data){
					dpaths = this.ImageDataParam.data.filter(function(current){
						return self.RightActiveRid.indexOf(current.rid)>-1;
					})
				}
				let paths = [];
				for (let index = 0; index < dpaths.length; index++) {
					const element = dpaths[index];
					paths.push(element.dpath);
				}
				paths = paths.join(',');
				var res = await axios.post('{MOD_URL}&op=library&do=ajax&operation=setfilelevel',{
					level:val,
					paths:paths,
					appid:this.DocumentAppid
				});
				if(res.data.success){
					this.RightData.level = val;
					for(var r in self.RightActiveRid){
						self.$refs.RefImageLayout.UpdateData(self.RightActiveRid[r],'level',val);
					}
				}else{
					self.$message.error(res.data.msg || '保存失败');
				}
			},
			
		}
	}
</script>